# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=soci
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.0.0
pkgrel=1
pkgdesc="SOCI - The C++ Database Access Library (mingw-w64)"
arch=('any')
url="https://soci.sourceforge.io/"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-firebird2-git"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-sqlite3")
depends=("${MINGW_PACKAGE_PREFIX}-boost")
optdepends=("${MINGW_PACKAGE_PREFIX}-firebird2-git"
            "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
            "${MINGW_PACKAGE_PREFIX}-postgresql"
            "${MINGW_PACKAGE_PREFIX}-sqlite3")
source=("${_realname}-${pkgver}.tar.gz::https://codeload.github.com/SOCI/soci/tar.gz/${pkgver}"
        soci-4.0.0.patch)
sha256sums=('359b988d8cbe81357835317821919f7e270c0705e41951a92ac1627cb9fe8faf'
            'e637829d76f9f2d57d98771a7ab71acc5df86e765fc6edbe23673ae34608c928')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/soci-4.0.0.patch
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE="Release" \
    -DSOCI_TESTS=OFF \
    "../${_realname}-${pkgver}"

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
